﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace SMS.Views.Reports
{
    public partial class ProductSaleReport : Page
    {
        ViewModel.Reports.ProductSaleReportViewModel _viewModel;
        public ProductSaleReport()
        {
            InitializeComponent();
            _viewModel = new ViewModel.Reports.ProductSaleReportViewModel();
            this.DataContext = _viewModel;
            _viewModel.OnReportChanged += new Action<string>(_viewModel_OnOptionChanged);
        }
        void _viewModel_OnOptionChanged(string obj)
        {
            grd_productSaleReport.Columns[0].Visibility = Visibility.Collapsed;
            grd_productSaleReport.Columns[1].Visibility = Visibility.Collapsed;
            grd_productSaleReport.Columns[2].Visibility = Visibility.Collapsed;
            grd_productSaleReport.Columns[3].Visibility = Visibility.Collapsed;
            grd_productSaleReport.Columns[4].Visibility = Visibility.Collapsed;
            grd_productSaleReport.Columns[5].Visibility = Visibility.Collapsed;
            switch (_viewModel.SelectedSearchOption)
            {
                case "Monthly":
                    grd_productSaleReport.Columns[0].Visibility = Visibility.Visible;
                    break;
                case "Weekly":
                    grd_productSaleReport.Columns[1].Visibility = Visibility.Visible;
                    break;
                case "Daily":
                    grd_productSaleReport.Columns[2].Visibility = System.Windows.Visibility.Visible;
                    break;
                case "Quarterly":
                    grd_productSaleReport.Columns[3].Visibility = System.Windows.Visibility.Visible;
                    break;
                case "Half Yearly":
                    grd_productSaleReport.Columns[4].Visibility = System.Windows.Visibility.Visible;
                    break;
                case "Yearly":
                    grd_productSaleReport.Columns[5].Visibility = System.Windows.Visibility.Visible;
                    break;
            }
        }
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.ContainsKey("option"))
            {
                _viewModel.SelectedSearchOption = NavigationContext.QueryString["option"];
                if (NavigationContext.QueryString.ContainsKey("fromdate"))
                    _viewModel.FromDate = Convert.ToDateTime(NavigationContext.QueryString["fromdate"]);
                if (NavigationContext.QueryString.ContainsKey("todate"))
                    _viewModel.EndDate = Convert.ToDateTime(NavigationContext.QueryString["todate"]);
            }
            _viewModel.SearchCommand.Execute(string.Empty);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Chart.Visibility = Visibility.Visible;
            grd_productSaleReport.Visibility = Visibility.Collapsed;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Chart.Visibility = Visibility.Collapsed;
            grd_productSaleReport.Visibility = Visibility.Visible;
        }
    }
}
